package com.flea.hclv.controller;

import com.flea.hclv.model.entity.HLine;
import com.flea.hclv.model.entity.HSubmitAccount;
import com.flea.hclv.service.HSubmitAccountService;
import com.flea.hclv.util.ServerResponse;
import com.flea.system.bean.FleaPage;
import com.flea.system.entity.OrgDept;
import com.flea.system.platform.session.FleaOrgUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @program: project
 * @description: 报销单
 * @author: shiliqiang
 * @create: 2019-01-03 16:18
 * @version: 1.0
 */
@Controller
@RequestMapping("/flea/hclv/submit/account/")
public class HSubmitAccountController {

    @Autowired
    private HSubmitAccountService hSubmitAccountService;

    @RequestMapping("createSubmitAccount")
    @ResponseBody
    public ServerResponse<HLine> createAssignGroupList(HttpServletRequest request, String model){
        String userId = FleaOrgUtils.getCurUserUuid(request);
        ServerResponse<HLine> response = hSubmitAccountService.save(userId,model);
        return response;
    }
    //通过团ID查看详情
    @RequestMapping("selectByGroupId")
    @ResponseBody
    public ServerResponse<Map<String,Object>> selectByGroupId(HttpServletRequest request,String submitAccountId){
//        String userId = FleaOrgUtils.getCurUserUuid(request);
        ServerResponse<Map<String,Object>> response = hSubmitAccountService.selectByGroupId(submitAccountId);
        return response;
    }
    //通过报账单id查看详情
    @RequestMapping("selectById")
    @ResponseBody
    public ServerResponse<Map<String,Object>> selectById(HttpServletRequest request,String submitAccountId){
//        String userId = FleaOrgUtils.getCurUserUuid(request);
        ServerResponse<Map<String,Object>> response = hSubmitAccountService.selectById(submitAccountId);
        return response;
    }

    //当前用户的报账单
    @RequestMapping("selectByCreateUser")
    @ResponseBody
    public ServerResponse<FleaPage<HSubmitAccount>> selectByCreateUser(HttpServletRequest request, FleaPage<HSubmitAccount> paging){
        String userId = FleaOrgUtils.getCurUserUuid(request);
        ServerResponse<FleaPage<HSubmitAccount>> response = hSubmitAccountService.selectByCreateUser(userId,paging.getCurPage(),paging.getCurPage());
        return response;
    }
    //当前部门的报账单
    @RequestMapping("selectByDeptId")
    @ResponseBody
    public ServerResponse<FleaPage<HSubmitAccount>> selectByDeptId(HttpServletRequest request,FleaPage<HSubmitAccount> paging){
        OrgDept currentUserDept = FleaOrgUtils.getCurrentUserDept(request);
        if (currentUserDept==null){
            return ServerResponse.createByErrorMessage("部门信息为空");
        }
        ServerResponse<FleaPage<HSubmitAccount>> response = hSubmitAccountService.selectByDeptId(currentUserDept.getDeptUuid(),paging.getCurPage(),paging.getCurPage());
        return response;
    }

    //获取线路
    @RequestMapping("selectLineByTravelGroupId")
    @ResponseBody
    public ServerResponse<HLine> selectLineByTravelGroupId(HttpServletRequest request,String travelGroupId){
//        OrgDept currentUserDept = FleaOrgUtils.getCurrentUserDept(request);
//        if (currentUserDept==null){
//            return ServerResponse.createByErrorMessage("部门信息为空");
//        }
        ServerResponse<HLine> response = hSubmitAccountService.selectLineByTravelGroupId(travelGroupId);
        return response;
    }



}
